cmake_minimum_required(VERSION 3.14)

project(SC_SUN LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(WIN32)
    add_definitions(
        -DWIN32
        -D_WIN32_WINNT=0x0A00
        -DYAML_CPP_STATIC_DEFINE
        -D_CRT_SECURE_NO_WARNINGS
        -DUWS_NO_ZLIB
        #-DLIBUS_NO_SSL
        -DLIBUS_USE_OPENSSL
        -DLIBUS_USE_LIBUV
    )
else(LINUX)
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    add_definitions(
      -DYAML_CPP_STATIC_DEFINE
      -D_CRT_SECURE_NO_WARNINGS
      -DUWS_NO_ZLIB
      #-DLIBUS_NO_SSL
      -DLIBUS_USE_OPENSSL
      -DLIBUS_USE_LIBUV
  )
endif()

include_directories(./Third/yaml/include/)     #yaml-cpp
include_directories(./Third/boost_1_82_0_build/include/boost-1_82/) #boost
include_directories(./Third/uWebSocket/uWebSockets/uSockets/src/)
include_directories(./Third/uWebSocket/uWebSockets/src/)
include_directories(./Third/rapidjson/include/)

add_executable(SC_SUN
  main.cpp
  ./DataBase/TimePoint.hpp
  ./DataBase/EvInputData.hpp
  ./DataBase/EvSceneData.hpp
  ./DataBase/EvSatelliteCLData.hpp
  ./DataBase/EvSatelliteORBData.hpp
  ./DataBase/EvSatelliteSIData.hpp
  ./DataBase/EvSatelliteData.hpp
  ./DataBase/EvGnssSNDataSub.hpp
  ./DataBase/EvSecIslSNDataSub.hpp
  ./DataBase/EvGnssSNData.hpp
  ./DataBase/EvSecIslSNData.hpp

  ./MapServer/SatelliteMGR.hpp
  ./MapServer/SatelliteMGR.cpp
  ./MapServer/GnssMGR.hpp
  ./MapServer/GnssMGR.cpp
  ./MapServer/SecIslSNMGR.hpp
  ./MapServer/SecIslSNMGR.cpp
  ./MapServer/MapService.hpp
  ./MapServer/MapService.cpp
  ./MapServer/MapHandler.hpp
  ./MapServer/MapHandler.cpp
  ./MapServer/Service.hpp
  ./MapServer/Service.cpp
  ./MapServer/SessionMgr.hpp
  ./MapServer/SessionMgr.cpp
  ./MapServer/CommandHandler.hpp
  ./MapServer/CommandHandler.cpp
  ./MapServer/MapApp.hpp
  ./MapServer/MapApp.cpp
  ./Protocol/MapProtocol.hpp
  ./Protocol/MapProtocol.cpp
  ./Protocol/Seralize.hpp
  ./Protocol/Seralize.cpp
  ./MapServer/Keti2Mgr.hpp
  ./MapServer/Keti2Mgr.cpp

  ./FuncServer/RpcClient.hpp
  ./FuncServer/RpcClient.cpp
  ./FuncServer/FuncService.hpp
  ./FuncServer/FuncService.cpp
  ./FuncServer/FuncHandler.hpp
  ./FuncServer/FuncHandler.cpp
  ./FuncServer/FuncApp.hpp
  ./FuncServer/FuncApp.cpp
  ./FuncServer/SceneSim.hpp
  ./FuncServer/SceneSim.cpp
)

#Message(${CMAKE_BUILD_TYPE})

include_directories(./Base)
add_subdirectory(./Base)

if(WIN32)

target_link_libraries(SC_SUN Iphlpapi)
target_link_libraries(SC_SUN Dbghelp)
target_link_libraries(SC_SUN Userenv)
target_link_libraries(SC_SUN Crypt32)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_directories(SC_SUN PUBLIC ./Third/uWebSocket/OpenSSL/lib/Debug/)
    target_link_directories(SC_SUN PUBLIC ./Third/uWebSocket/uWebSockets/build/libuv/Debug/)
    target_link_directories(SC_SUN PUBLIC ./Third/uWebSocket/uWebSockets/build/uSockets/Debug/)
else()
    target_link_directories(SC_SUN PUBLIC ./Third/uWebSocket/OpenSSL/lib/Release/)
    target_link_directories(SC_SUN PUBLIC ./Third/uWebSocket/uWebSockets/build/libuv/Release/)
    target_link_directories(SC_SUN PUBLIC ./Third/uWebSocket/uWebSockets/build/uSockets/Release/)
endif()
target_link_libraries(SC_SUN libssl)
target_link_libraries(SC_SUN libcrypto)
target_link_libraries(SC_SUN libuv)
target_link_libraries(SC_SUN usockets)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
    target_link_directories(SC_SUN PRIVATE ./Third/yaml/build/Release/)
else()
    target_link_directories(SC_SUN PRIVATE ./Third/yaml/build/Debug/)
endif()
target_link_libraries(SC_SUN mmf_base yaml-cpp)

else(LINUX)

    target_link_libraries(SC_SUN libssl.a)
    target_link_libraries(SC_SUN libcrypto.a)
    target_link_directories(SC_SUN PRIVATE ./Third/uWebSocket/uWebSockets/build/uSockets/)
    target_link_libraries(SC_SUN usockets)
    target_link_directories(SC_SUN PRIVATE ./Third/uWebSocket/uWebSockets/build/libuv/)
    target_link_libraries(SC_SUN libuv.a)
    target_link_directories(SC_SUN PRIVATE ./Third/yaml/build/)
    target_link_libraries(SC_SUN yaml-cpp.a)
    target_link_libraries(SC_SUN mmf_base)

endif()

include(GNUInstallDirs)
install(TARGETS SC_SUN
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
